<?php

abstract class View
{
	private $oStyles;
	private $oScripts;
	
	public function __construct()
	{
		$this->oStyles = array();
		$this->oScripts = array();
	}
	
	abstract public function html();
	
	public function addCss($css)
	{
		$this->oStyles[] = $css;
	}
	
	public function addScript($script)
	{
		$this->oScripts[] = $script;
	}
	
	protected function styles()
	{
		foreach ($this->oStyles as $css)
		{
			?>
			<link rel="stylesheet" href="<?php echo STYLE_PATH . "/" . $css . ".css"; ?>" />
			<?php
		}
	}
	
	/** Размещает скрипты */
	protected function scripts()
	{
		foreach ($this->oScripts as $script)
		{
			?>
			<script type="text/javascript" src="<?php echo SCRIPTS_PATH . "/" . $script; ?>"></script>
			<?php
		}
	}
	
	abstract protected function name();
	
	protected function url($params = array(), $echo = true)
	{
		$url = null;
		if (!array_key_exists("view", $params))
			$url = "?view=" . $this->name();
		foreach ($params as $key => $val)
		{
			if (is_null($url))
				$url = "?" . $key . "=" . $val;
			else
				$url .= "&" . $key . "=" . $val;
		}
		if (!$echo)
			return $url;
		echo $url;
	}
} 

?>